from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import HttpResponse,redirect,render

class AuthMiddleware(MiddlewareMixin):
    """中间件"""
    def process_request(self,request):
        #0、排除不需要登录验证就能访问的页面
        if request.path_info in ["/login/","/image/code/"]:
            return
        #1、读取当前访问的用户的session信息，如果能读到，说明已登录过，就可以继续向后走
        info_dict = request.session.get("info")
        if info_dict:
            return
        # 2、没登录过,重新登录
        return redirect("/login/")